﻿using Basic.FlowApplication.Interface;
using Basic.FlowCollect;
using Basic.FlowExtendService;
using Basic.FlowModel.AuditSign;
using Basic.FlowRemoteModel.Application.Model;
using WeDonekRpc.Helper;

namespace Basic.FlowApplication.lmpl
{
    internal class AuditSignLogService : IAuditSignLogService
    {
        private readonly IFlowAuditSignLogCollect _SignLog;

        private readonly IFileService _File;

        public AuditSignLogService ( IFlowAuditSignLogCollect signLog, IFileService file )
        {
            this._SignLog = signLog;
            this._File = file;
        }

        public void Restore ( long logId, long optItemId )
        {
            SignFile[] file = this._SignLog.Restore(logId, optItemId);
            if ( !file.IsNull() )
            {
                this._File.Restore(file.ConvertAll(a => a.FileId));
            }
        }

        public void ToVoid ( long[] itemId, long optItemId )
        {
            SignFile[] file = this._SignLog.ToVoid(itemId, optItemId);
            if ( !file.IsNull() )
            {
                this._File.ToVoid(file.ConvertAll(a => a.FileId));
            }
        }

        public void TryAdd ( AuditSignFileLog add )
        {
            if ( this._SignLog.TryAdd(add) )
            {
                this._File.Save(add.FileId, add.LogId);
            }
        }

    }
}
